package com.project.yuepai.controller.admin;

import com.project.yuepai.dto.MessageBean;
import com.project.yuepai.service.DynamicService;
import com.project.yuepai.util.MessageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/admin/dynamic/")
public class DynamicController {

    @Autowired
    private DynamicService dynamicService;

    @RequestMapping(value = "/findAllDynamics.action",method = RequestMethod.GET)
    public MessageBean findAllDynamics(@NotNull(message = "页面数据条数不能为空") Integer limit, @NotNull(message = "页号不能为空") Integer page,
                                       String nickName, Integer userRole, String userPhone){
        System.out.println("获取到的数据-->"+dynamicService.findAllDynamics(page, limit, nickName, userRole, userPhone));
        return MessageUtil.success("获取成功！",dynamicService.findAllDynamics(page, limit, nickName, userRole, userPhone));
    }

    @RequestMapping(value = "/deleteDynamic.action",method = RequestMethod.DELETE)
    public MessageBean deleteFeedback(Integer dynamicId){
        System.out.println("dynamicId"+dynamicId);
        if(dynamicService.deleteDynamic(dynamicId))
            return MessageUtil.success("删除成功！");
        return MessageUtil.failure("删除失败！");
    }

}
